function initXFTPay(data) {
    return new Promise((resolve, reject) => {
        wx.request({
            url:
                data.ApiUrl ||
                "https://wx.test.91xft.cn/transaction/charge/self",
            data: {
                ...data
            },
            method: "POST",
            header: {
                "content-type": "application/json" // 默认值
            },
            success(res) {
                if (res.data.result) {
                    let { credential } = res.data.data;
                    credential = JSON.parse(credential);
                    if (credential.packageValue) {
                        wx.requestPayment({
                            timeStamp: credential.timeStamp,
                            nonceStr: credential.nonceStr,
                            package: credential.packageValue,
                            signType: credential.signType || "MD5",
                            paySign: credential.paySign,
                            success: function(res) {
                                console.log(res);
                            },
                            fail: function(res) {
                                // console.log(res);
                            },
                            complete: function(res) {
                                resolve(res);
                            }
                        });
                    }
                } else {
                    reject(res.data);
                }
            }
        });
    });
}

module.exports.initXFTPay = initXFTPay;
